package com.oocl.authority.filter;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.dao.MuserDao;
import com.oocl.dao.impl.MuserDaoImpl;
import com.oocl.pojo.Muser;


public class AuthorityFilter implements Filter {

   
    public AuthorityFilter() {
    	
    }

	
	public void destroy() {
		
	}

	
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest) request;
		HttpServletResponse resp = (HttpServletResponse) response;
		String mid = (String) req.getSession().getAttribute("mid");
		//System.out.println(mid);
		MuserDao mDao = new MuserDaoImpl();
		try {
			Muser m = mDao.loadMuserById(mid);
			//System.out.println(m.getStatus1());
			if("2".equals(m.getStatus1())){
				req.getRequestDispatcher("black.jsp").forward(req, resp);;
				return;
			}else{
				
				chain.doFilter(request, response);				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	
	public void init(FilterConfig fConfig) throws ServletException {
		
	}

}
